<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class AddressRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            "addr_province" => "required",
            "addr_detail" => "required",
            "addr_postcode" => "required|regex:/^\d{6}$/",
            "addr_consignee" => "required",
            "addr_tel" => "required|regex:/^1\d{10}$/",
        ];
    }
    
    public function messages() {
        return [
            "addr_province.required" => "请选择地址",
            "addr_detail.required" => "请填写详细地址",
            "addr_postcode.required" => "请填写邮编",
            "addr_postcode.regex" => "邮编必须为6位",
            "addr_consignee.required" => "姓名必须填写",
            "addr_tel.required" => "手机号必须填写",
            "addr_tel.regex" => "手机号格式错误",
        ];
    }
    
    public function validateInput($data)
    {
        $message = Validator::make($data, $this->rules(), $this->messages());
        return $message->errors();
    }
}
